package com.topisv.tms.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.topisv.tms.entity.Consignor;
import com.topisv.tms.repository.ConsignorDao;

/**
 * 发货人信息service
 * @author Administrator
 *
 */
//Spring Bean的标识.
@Component
// 默认将类中的所有public函数纳入事务管理.
@Transactional(readOnly = true)
public class ConsignorService {
	@Autowired
	private ConsignorDao consignorDao;

	public Consignor findConsignor(Consignor consignor){
		return consignorDao.findOne(consignor.getId());
	}
	
	public Consignor findConsignor(Long consignorId){
		return consignorDao.findOne(consignorId);
	}
	
	public Consignor findCustomersId(Long customersId){
		return consignorDao.findCustomersId(customersId);
	}
	
	public Consignor findCustomerCode(String customerCode){
		return consignorDao.findCustomerCode(customerCode);
	}
	
	public Iterable<Consignor> findAll(){
		return consignorDao.findAll();
	}
	
	@Transactional(readOnly = false)
	public Consignor saveConsignor(Consignor consignor) {
		if (consignor == null) {
			throw new IllegalArgumentException("consignor=" + consignor);
		}
		return consignorDao.save(consignor);
	}
}
